#ifndef __CONTAINER_H__
#define __CONTAINER_H__

#include "./inputhelper.h"
#include "graphics/graphics.h"
#include "graphics/bitmap.h"
#include "base/object.h"

namespace MiniUI
{

class UIObject;
class WinView;

class Container : public Object
{
public:
    Container();
    virtual ~Container();
public:
    virtual bool CreateContainer(const Type::MiniRect& rect) = 0;
    virtual void DestroyContainer() = 0;
    bool Bind(WinView* pView);
    virtual void* GetHost() = 0;
    virtual void Hide() = 0;
    virtual void Show() = 0;
    virtual void SetRect(const Type::MiniRect& rect) = 0;
    virtual void GetRect(Type::MiniRect& rect) const = 0;
    virtual void SetPos(const Type::MiniPoint& pt) = 0;
    virtual void GetPos(Type::MiniPoint& pt) const = 0;
    virtual void SetSize(const Type::MiniSize& sz) = 0;
    virtual void GetSize(Type::MiniSize& sz) const = 0;
    virtual void SetCaption(const char* szCaption) = 0;
    virtual void SetBorder(const Type::MiniRect& border) = 0;
    virtual void SetMaxSize(const Type::MiniSize& size) = 0;
    virtual void SetMinSize(const Type::MiniSize& size) = 0;
    virtual void SetTopMost(bool bTopMost) = 0;
    virtual bool IsTopMost() = 0;
    virtual void SetForegroundWindow() = 0;
    virtual void GetCursorPos(Type::MiniPoint& pt) = 0;
    virtual void SetCursor(CursorType cursor, void* customCursor = nullptr) = 0;
protected:
    void ListenViewEvent();
    void UnlistenViewEvent();
protected:
    void ViewChange(const UIObject* sender, const Type::MiniRect& rect);
protected:
    virtual void Update(const Type::MiniRect& rect) = 0;
    virtual void SyncRect() = 0;
protected:
    void DoClick(const Type::MiniPoint& pt, MouseButton button, uint keyState, bool& bHandled);
    void DoMouseDown(const Type::MiniPoint& pt, MouseButton button, uint keyState, bool& bHandled);
    void DoMouseUp(const Type::MiniPoint& pt, MouseButton button, uint keyState, bool& bHandled);
    void DoMouseMove(const Type::MiniPoint& pt, uint keyState, bool& bHandled);
    void DoMouseEnter();
    void DoMouseLeave();
    void DoMouseWheel(const Type::MiniPoint& pt, uint keyState, int16 zDelta, bool& bHandled);
    void DoActivate(bool bActivate);
    void DoClose();
public:
    Event<OnNotifyEventFunc> OnDragStart;
    Event<OnNotifyEventFunc> OnDragEnd;
    Event<OnNotifyEventFunc> OnWindowActivate;
protected:
    Graphics m_graphics;
    Bitmap* m_pBitmap;
    WinView* m_pWinView;
    //help object
    UIObject* m_pObjFocus;
    UIObject* m_pObjMouseDown;
    uint32 m_uLastClickTime;
    uint32 m_uLastClickTimes;
    Type::MiniPoint m_ptLastClickPos;
    MouseButton m_uLastButton;
};

}

#endif